\startenvironment doc-env

\usemodule[bib]

%% --------------------------- 中文字体
\usetypescriptfile[zhfonts]
\usetypescript[myfont]
\setupbodyfont[myfont,rm,12pt]

%% --------------------------- 交互设置
\setupcolors[state=start]
\setupcolor[hex]
\setupinteraction[state=start,
                  title={ConTeXt MkIV 中文文档模板},
                  subtitle={Using MkIV},
                  author={Liu Yubao},
                  keyword={ConTeXt MkIV LuaTeX Chinese},
                  focus=standard,
                  color=blue]
\setupinteractionscreen[option=bookmark]
\placebookmarks[chapter,section][chapter]


%% --------------------------- 版式
% 纸张
\setuppapersize[A4][A4]

% 布局
\setuplayout[width=fit,height=middle,
             leftmargin=3cm,rightmargin=3cm,
             backspace=4cm,topspace=2cm,
             headerdistance=.5cm,footerdistance=.5cm,
             leftmargindistance=.5cm,rightmargindistance=.5cm,
             header=1cm,footer=1cm]
% 目录
\setupcombinedlist[content][alternative=c]

% 页眉页脚
\startsetups HeaderFooter
    \def\CurrentChapter{%
        第 \headnumber[chapter]\ 章%
        \hbox to 2em{}%
        \getmarking[chapter]%
        }
    \def\CurrentSection{%
        \headnumber[section]%
        \hbox to 2em{}%
        \getmarking[section]%
        }
    \setuppagenumbering[style=\tfx,location=]
    \setupheadertexts[\CurrentChapter][pagenumber][\CurrentSection][pagenumber]
    \setupfootertexts[{\ConTeXt\ 文档模板}][{\goto{\bfx 目录}[Content]}]
                     [{\goto{\bfx 目录}[Content]}][{\ConTeXt\ 文档模板}]
    \setupheader[style=\bfx,color=darkgray]
    \setupfooter[style=\bfx,color=darkgray]
\stopsetups

% 章节标题
\setupheads[indentnext=yes]
\setuphead[chapter][style=\bfb,header=empty,footer=empty]
\setuphead[title][style=\bfb,header=empty,foote=empty]
\setuphead[section][style=\bfa]
\setuphead[subsubject][style=\bf]
\setupheadtext[en][pubs=参考文献]
\setupheadtext[en][content=目\;\;录]
\setupheadtext[en][index=索引]
\setuplabeltext[en][chapter={第\;,\;章}]
\setuplabeltext[en][figure=图\;]
\setuplabeltext[en][table=表\;]
\setupcaptions[style=\tfx,headstyle=\normal]

% 段落缩进、行间距、段落间距
\setupinterlinespace[big]
\setupwhitespace[big]
\setupindenting[always,first,2em]
\setupfloats[indentnext=yes] 

%% --------------------------- 参考文献
\setupbibtex[database=bibliography]
\setuppublications[alternative=num]
\setuppublicationlayout[booklet]{%
    \insertauthors{}{\unskip.}{}%
    \inserttitle{ \bgroup\it }{\/\egroup\unskip.}{}%
    \insertbiburl{ URL: }{\unskip.}{}%
    \insertnote{ }{\unskip.}{}}

\setuppublicationlayout[manual]{%
    \insertauthors{}{\unskip.}{}%
    \inserttitle{ \bgroup\it }{\/\egroup\unskip.}{}%
    \insertbiburl{ URL: }{\unskip.}{}%
    \insertnote{ }{\unskip.}{}}

%% --------------------------- 杂项
%\setuptolerance[horizontal,stretch]
%\setupexternalfigures[directory={./figures}]

%% 代码环境
\setuplinenumbering[color=darkgray,style=small]
\setuptyping[option=color,palet=graypretty,
             before={\blank[.5em]\setupinterlinespace[medium]},
             after={\blank[.5em]}]
\definetyping[niceTEX][option=TEX]

%% 阴影盒
\startuniqueMPgraphic{shade box}
    path p;
    u := 1cm; w := \overlaywidth; h := \overlayheight;
    roundcorner := 8pt; offset := 12pt;
    
    color shade;
    shade := (.6,.6,.6);

    for i = 0 step .02 until 1:
        fill unitsquare xyscaled (w-i*u,h-i*u) squeezed (8pt,6pt) 
             shifted (offset+i*u/2,-offset+i*u/2)
             withcolor transparent (1,.1,shade);
    endfor;

    p := unitsquare xyscaled (w, h);
    draw p withcolor transparent (1,0,white);

    p := p shifted (offset/2, -offset/2) squeezed (8pt,6pt);
    fill p withcolor \MPcolor{darkgray};
    draw p withcolor \MPcolor{OrnamentColor};
\stopuniqueMPgraphic
\defineoverlay[shade box][\uniqueMPgraphic{shade box}]
\setupframedtexts[frame=off,background={shade box}]

\stopenvironment

